package com.smec.remes.module.submit;

import android.content.Context;

import com.smec.remes.base.SmecBasePresenter;
import com.smec.remes.bean.NewPackingList;
import com.smec.remes.bean.SmecLogBean;
import com.smec.remes.bean.SubmitDetails;
import com.smec.remes.bean.SubmitFinish;
import com.smec.remes.bean.SubmitSure;
import com.smec.remes.smecManager.SmecRetrofit.BaseSubscriber;
import com.smec.remes.smecManager.SmecRetrofit.HttpResult;

import java.util.ArrayList;
import java.util.HashMap;

import rx.Observable;

import static com.smec.remes.module.submit.activity.SmecLogActivity.GET_LOG_SUCCESS;

/**
 * Created by Administrator on 2017/12/18.
 */

public class SmecSubmitPresenter extends SmecBasePresenter {
    public SmecSubmitPresenter(Context mContext) {
        super(mContext);
    }

    public void _sure(String confirmNo){
        HashMap<String, Object> map = new HashMap<>();
        map.put("confirmNo", confirmNo);
        Observable<HttpResult> observable=smecPackingService._surePacking(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult>() {
            @Override
            public void onNext(HttpResult httpResult) {
                String a=httpResult.getCode();
                mRxbus.post("SURE",a);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("SUREFAIL","");
            }
        });
    }

    public void submitRequest(String condition,String type,int pageNumber) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("condition", condition);
        map.put("type", type);
        map.put("pageSize", 10);
        map.put("pageNumber", pageNumber);
        Observable<HttpResult<ArrayList<SubmitFinish>>> observable = smecPackingService.submitRequest(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SubmitFinish>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SubmitFinish>> arrayListHttpResult) {
                ArrayList<SubmitFinish> submitFinishArrayList=arrayListHttpResult.getData();
                mRxbus.post("UNFINISH",submitFinishArrayList);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("UNFINISHFAIL","FAIL");
            }
        });
    }

    public void _submitRequest(String condition,String type,int pageNumber) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("condition", condition);
        map.put("type", type);
        map.put("pageSize", 10);
        map.put("pageNumber", pageNumber);
        Observable<HttpResult<ArrayList<SubmitFinish>>> observable = smecPackingService.submitRequest(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SubmitFinish>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SubmitFinish>> arrayListHttpResult) {
                ArrayList<SubmitFinish> submitFinishArrayList=arrayListHttpResult.getData();
                mRxbus.post("FINISH",submitFinishArrayList);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("FINISHFAIL","FAIL");
            }
        });
    }

    public void _submitDetails(String applyOrderNo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("applyOrderNo", applyOrderNo);
        Observable<HttpResult<ArrayList<SubmitDetails>>> observable = smecPackingService.submitDetails(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SubmitDetails>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SubmitDetails>> arrayListHttpResult) {
                ArrayList<SubmitDetails> arrayList=arrayListHttpResult.getData();
                mRxbus.post("DETAILS",arrayList);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("DETAILSFAIL","FAIL");
            }
        });
    }

    public void _packing(String confirmNo){
        HashMap<String, Object> map = new HashMap<>();
        map.put("confirmNo", confirmNo);
        Observable<HttpResult<NewPackingList>> observable=smecPackingService._packing(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<NewPackingList>>() {
            @Override
            public void onNext(HttpResult<NewPackingList> arrayListHttpResult) {
                mRxbus.post("PACKING",arrayListHttpResult);
            }
        });
    }

    public void _weishouhuoDetails(String applyOrderNo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("applyOrderNo", applyOrderNo);
        Observable<HttpResult<ArrayList<SubmitDetails>>> observable = smecPackingService.submitDetails(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SubmitDetails>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SubmitDetails>> arrayListHttpResult) {
                ArrayList<SubmitDetails> arrayList=arrayListHttpResult.getData();
                mRxbus.post("W_DETAILS",arrayList);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("W_DETAILSFAIL","FAIL");
            }
        });
    }

    public void _shouhuoDetails(String applyOrderNo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("applyOrderNo", applyOrderNo);
        Observable<HttpResult<ArrayList<SubmitDetails>>> observable = smecPackingService.submitDetails(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SubmitDetails>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SubmitDetails>> arrayListHttpResult) {
                ArrayList<SubmitDetails> arrayList=arrayListHttpResult.getData();
                mRxbus.post("SHOUHUO",arrayList);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("SHOUHUOFAIL","FAIL");
            }
        });
    }

    public void _submitSure(SubmitSure submitSure) {

        Observable<HttpResult> observable = smecPackingService._submitSure(submitSure);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult>() {
            @Override
            public void onNext(HttpResult httpResult) {
                mRxbus.post("SHOUHUO",httpResult);
            }

            @Override
            public void onError(Throwable e) {
                super.onError(e);
                mRxbus.post("SHOUHUOFAIL","FAIL");
            }
        });
    }

    public void _backDetails(String applyOrderNo) {
        HashMap<String, Object> map = new HashMap<>();
        map.put("applyOrderNo", applyOrderNo);
        Observable<HttpResult<ArrayList<SubmitDetails>>> observable = smecPackingService.submitDetails(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SubmitDetails>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SubmitDetails>> arrayListHttpResult) {
                ArrayList<SubmitDetails> arrayList=arrayListHttpResult.getData();
                mRxbus.post("backDetails",arrayList);
            }
        });
    }

    /**
     * 获取日志信息
     * @param applyOrderNo
     */
    public void getLog(String applyOrderNo){
        HashMap<String, Object> map = new HashMap<>();
        map.put("applyOrderNo", applyOrderNo);
        Observable<HttpResult<ArrayList<SmecLogBean>>> observable=smecPackingService.getLog(map);
        schedulerThread(observable).subscribe(new BaseSubscriber<HttpResult<ArrayList<SmecLogBean>>>() {
            @Override
            public void onNext(HttpResult<ArrayList<SmecLogBean>> arrayListHttpResult) {
                mRxbus.post(GET_LOG_SUCCESS,arrayListHttpResult.getData());
            }
        });
    }
}
